Complete the following steps:
- Add x:Name="C1ComboBox1" to the <c1:C1ComboBox> tag so that the object will have a unique identifier for you to call in code.
- Open the MainWindow.Xaml.cs page or the MainPage.xaml.cs page (or the .vb page if using Visual Basic).
- Import the following namespace into the project:
| Visual Basic |
Copy Code
|
Imports System.Collections.Generic
|
| C# |
Copy Code
|
using System.Collections.Generic;
|
- Create your list by adding the following code beneath the InitializeComponent() method:
| Visual Basic |
Copy Code
|
Dim dropDownList As New List(Of String)()
dropDownList.Add("C1ComboBoxItem1")
dropDownList.Add("C1ComboBoxItem2")
dropDownList.Add("C1ComboBoxItem3")
dropDownList.Add("C1ComboBoxItem4")
|
| C# |
Copy Code
|
List<string> dropDownList = new List<string>();
dropDownList.Add("C1ComboBoxItem1");
dropDownList.Add("C1ComboBoxItem2");
dropDownList.Add("C1ComboBoxItem3");
dropDownList.Add("C1ComboBoxItem4");
|
- Add the list to the combo box by setting the ItemsSource property:
| Visual Basic |
Copy Code
|
C1ComboBox1.ItemsSource = dropDownList
|
| C# |
Copy Code
|
c1ComboBox1.ItemsSource = dropDownList;
|
- Run the program.
Complete the following steps:
- In the Properties window, click the Items ellipsis button
to open the Collection Editor: Items dialog box.
Collection Editor: Items
|
- Click Add to add a C1ComboBoxItem to the C1ComboBox control.